package org.hxyjs.service.impl;


import org.hxyjs.dao.AdvertisersDao;
import org.hxyjs.dto.DTO;
import org.hxyjs.dto.MessageEnum;
import org.hxyjs.entity.Account;
import org.hxyjs.entity.Advertisers;
import org.hxyjs.entity.Advertisers;
import org.hxyjs.entity.Parents;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.AccountService;
import org.hxyjs.service.AdvertisersService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service("advertisersService")
public class AdvertisersServiceImpl implements AdvertisersService, AccountService {
    @Resource
    AdvertisersDao advertisersDao;
    @Override
    public DTO<Advertisers> getAllAdvertiserss()  throws Exception{
        List<Advertisers> advertiserss = advertisersDao.getAllAdvertiserss();
        MessageEnum messageEnum  = Optional.ofNullable(advertiserss).isPresent()?MessageEnum.GETADVERTISERSSUCCESS: MessageEnum.GETADVERTISERSFAIL;
        return new DTO<Advertisers>(messageEnum.getCode(),messageEnum.getMessage(),advertiserss);
    }

    @Override
    public DTO<Advertisers> deleteAdvertisersByAdno(String adno)  throws Exception{
        Integer result = advertisersDao.deleteAdvertisersByAdno(adno);
        MessageEnum messageEnum  =result> 0?MessageEnum.DELETEADVERTISERSSUCCESS:MessageEnum.DELETEADVERTISERSFAIL;
        return new DTO<Advertisers>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Advertisers> updateAdvertisersByAdno(Advertisers advertisers)  throws Exception{
        Integer result = advertisersDao.updateAdvertisersByAdno(advertisers);
        MessageEnum messageEnum  =result> 0?MessageEnum.UPDATEADVERTISERSSUCCESS:MessageEnum.UPDATEADVERTISERSFAIL;
        return new DTO<Advertisers>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Advertisers> addAdvertisers(Advertisers advertisers) throws Exception {
        Integer result = advertisersDao.addAdvertisers(advertisers);
        MessageEnum messageEnum  = result> 0?MessageEnum.ADDADVERTISERSSUCCESS:MessageEnum.ADDADVERTISERSFAIL;
        return new DTO<Advertisers>(messageEnum.getCode(),messageEnum.getMessage());
    }
    @Override
    public DTO<Advertisers> getAdvertisersByPage(PageInfo pageInfo ) throws Exception {
        List<Advertisers> advertiserss = advertisersDao.getAdvertisersByPage(pageInfo);
        MessageEnum messageEnum  = Optional.ofNullable(advertiserss).isPresent()?MessageEnum.GETADVERTISERSSUCCESS: MessageEnum.GETADVERTISERSFAIL;
        return new DTO<Advertisers>(messageEnum.getCode(),messageEnum.getMessage(),advertiserss,pageInfo);
    }

    @Override
    public DTO<Account> getAccountByAccountName(String accountName) throws Exception {
        Advertisers advertiserss = advertisersDao.getAccountByAccountName(accountName);
        MessageEnum messageEnum  = Optional.ofNullable(accountName).isPresent()?MessageEnum.GETPARENTSSUCCESS:MessageEnum.GETPARENTSFAIL;
        return new DTO<Account>(messageEnum.getCode(),messageEnum.getMessage(),advertiserss);
    }
}
